#include "StdAfx.h"
#include "List.h"
#include "Factory.h"

using namespace Torrent::Bencode;

List::List(std::istream& stream)
{
    while (stream.good()) 
    {
        stream.get();
        if (stream.peek() == 'e') 
        {
            stream.get();
            return;
        }

        _list.push_back(Factory::create(stream));
    }
}

List::~List(void)
{
}

void List::print( std::ostream& stream, bool debug /*= false*/ )
{
    stream << "l";

    std::list<ListElement>::iterator it;
    for (it = _list.begin(); it != _list.end(); ++it)
    {
        (*it)->print(stream,debug);
    }
    
    stream << "e";

}